#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<assert.h>
#include<vector>
#include<algorithm>
using namespace std;
#include"list.h"

void test1()
{
	cx::list<int> l1;
	l1.push_back(1);
	l1.push_back(2);
	l1.push_back(3);
	l1.push_back(4);
	cx::list<int>::iterator it1 = l1.begin();

	for (const auto& e : l1)
	{
		cout << e << ' ';
	}
	cout << endl;

	l1.pop_back();
	l1.pop_back();
	l1.pop_back();
	l1.pop_back();
	l1.pop_back();
	for (const auto& e : l1)
	{
		cout << e << ' ';
	}
	cout << endl;

	//cout << typeid(l1.begin()).name() << endl;
	//cout << typeid(it1).name() << endl;


}


void test2()
{
	cx::list<int> l1;
	
	l1.push_back(1);
	l1.push_back(2);
	l1.push_back(3);
	l1.push_back(4);

	/*vector<int> v1 = { 100,200,300,400};
	auto it1 = find(v1.begin(), v1.end(), 300);*/

	cx::list<int>::iterator it1 = l1.begin();
	while (it1 != l1.end())
	{
		if (*it1 == 3)
		{
			break;
		}
		++it1;
	}
	
	it1 = l1.insert(it1, 100);
	it1 = l1.insert(it1, 200);
	it1 = l1.insert(it1, 300);

	/*for(int i = 0; i < 4; i++)
	{
		it1 = l1.insert(it1, v1[i]);
	}*/

	for (const auto& e : l1)
	{
		cout << e << ' ';
	}
	cout << endl;

	l1.erase(it1);

	for (const auto& e : l1)
	{
		cout << e << ' ';
	}
	cout << endl;
}


void fun(const cx::list<int>& l1)
{
	cx::list<int>::const_iterator it1 = l1.begin();

	while (it1 != l1.end())
	{
		cout << *it1 << ' ';
		it1++;
	}
	cout << endl;

	it1 = l1.begin();



}


void test3()
{
	cx::list<int> l1;

	l1.push_back(1);
	l1.push_back(2);
	l1.push_back(3);
	l1.push_back(4);

	//fun(l1);

	/*l1.erase(l1.begin());
	l1.pop_back();
	for (auto e : l1)
	{
		cout << e << ' ';
	}
	cout << endl;*/

	l1.pop_front();
	l1.push_front(1000);

	for (auto e : l1)
	{
		cout << e << ' ';
	}
	cout << endl;
	l1.reserve();
	for (auto e : l1)
	{
		cout << e << ' ';
	}
	cout << endl;
}


void fun1(const cx::list<int>& lt)
{
	cx::list<int>::const_reverse_iterator it1 = lt.rbegin();
	while (it1 != lt.rend())
	{
		cout << *it1 << ' ';
		it1++;
	}
	cout << endl;
}

void test4()
{
	cx::list<int> l1;

	l1.push_back(1);
	l1.push_back(2);
	l1.push_back(3);
	l1.push_back(4);
	
	fun1(l1);

}


struct information
{
	int _age;
	double _score;
	information(int age = 0, int score = 0)
		:_age(age)
		,_score(score)
	{}
};

void test5()
{
	cx::list<information> l1;

	l1.push_back({ 1, 100 });
	l1.push_back({ 2, 200 });
	l1.push_back({ 3, 300 });
	l1.push_back({ 4, 400 });

	cx::list<information>::reverse_iterator it1 = l1.rbegin();
	while (it1 != l1.rend())
	{
		cout << it1->_age << ' ' << it1->_score << endl;
		it1++;
	}


}

void test6()
{
	vector<int> v1 = { 1,2,23,4,5,6 };
	cx::list<int> l2 = { 1,2,3,4,5,6 };
	cx::list<int> l1(l2.begin(), l2.end());

	for (auto& e : l1)
	{
		e++;
		cout << e << ' ';
	}
	cout << endl;

	cout << l2.size() << endl;
	cout << l2.empty() << endl;
	cout << l2.front() << endl;
	cout << l2.back() << endl;
	for (auto e : l1)
	{
		cout << e << ' ';
	}
	cout << endl;
	l1.swap(l2);
	for (auto e : l2)
	{
		cout << e << ' ';
	}
	cout << endl;

}



void test7()
{
	cx::list<int> l2 = { 1,2,1,3,2,4,1,2 };


	for (auto e : l2)
	{
		cout << e << endl;
	}

}

int main()
{
	//test1();
	//test3();
	//test4();
	
	//test5();

	test7();

	return 0;
}